Skip to content

PTHMINT-99: Use PEP 585 built-in generics#46

Open
zulquer wants to merge 3 commits intomasterfrom
PTHMINT-99
Open

PTHMINT-99: Use PEP 585 built-in generics#46
zulquer wants to merge 3 commits intomasterfrom
PTHMINT-99

Conversation

@zulquer
Copy link
Collaborator

@zulquer zulquer commented Feb 27, 2026

Migrate typing annotations to built-in generics (list, dict, etc.) and tidy imports across the codebase for Python 3.9+ compatibility. Updated various modules to replace typing.List/Dict/Type/Iterator with modern equivalents, adjusted some Optional and Union hints, and simplified imports. Added [tool.ruff] target-version = "py39" to pyproject.toml. Also tightened tests: assert recurring_id presence and use identity check for boolean in an assertion.

Migrate typing annotations to built-in generics (list, dict, etc.) and tidy imports across the codebase for Python 3.9+ compatibility. Updated various modules to replace typing.List/Dict/Type/Iterator with modern equivalents, adjusted some Optional and Union hints, and simplified imports. Added [tool.ruff] target-version = "py39" to pyproject.toml. Also tightened tests: assert recurring_id presence and use identity check for boolean in an assertion.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes type annotations by migrating from typing module generics (List, Dict, Type, Iterator) to PEP 585 built-in generics (list, dict, type) and collections.abc.Iterator, enabling Python 3.9+ compatibility. The changes improve code maintainability by using modern Python type hint syntax. Additionally, test assertions are strengthened to verify the presence of recurring_id and use identity checks for boolean comparisons.

Changes:

  • Replaced typing.List, typing.Dict, typing.Type with built-in list, dict, type across 14 files
  • Migrated typing.Iterator to collections.abc.Iterator in 2 files
  • Added target-version = "py39" to pyproject.toml Ruff configuration
  • Enhanced test assertions for recurring_id presence and boolean identity checks

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyproject.toml Added Ruff target-version configuration for Python 3.9
tests/multisafepay/e2e/examples/recurring_manager/test_recurring.py Added recurring_id assertion and improved boolean comparison
src/multisafepay/value_object/decimal_amount.py Updated Type to type in validator
src/multisafepay/util/message.py Replaced List/Dict with list/dict, Iterator from collections.abc
src/multisafepay/util/address_parser.py Replaced List with list
src/multisafepay/exception/api.py Replaced Dict/List with dict/list
src/multisafepay/client/client.py Replaced Dict with dict, added Optional for context param
src/multisafepay/api/shared/checkout/tax_rule.py Replaced List/Dict with list/dict
src/multisafepay/api/shared/checkout/checkout_options.py Replaced List with list
src/multisafepay/api/shared/cart/shopping_cart.py Replaced List with list
src/multisafepay/api/paths/transactions/response/transaction.py Replaced List with list
src/multisafepay/api/paths/payment_methods/response/payment_method.py Replaced List with list
src/multisafepay/api/paths/payment_methods/response/components/brand.py Replaced List with list
src/multisafepay/api/paths/orders/response/order_response.py Replaced List with list
src/multisafepay/api/paths/orders/order_id/refund/request/components/checkout_data.py Replaced List with list
src/multisafepay/api/base/response/custom_api_response.py Replaced Dict with dict
src/multisafepay/api/base/listings/listing.py Replaced List/Dict/Iterator with list/dict/collections.abc.Iterator
src/multisafepay/api/base/decorator.py Replaced Dict/List with dict/list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pyproject.toml Outdated
Comment on lines +139 to +140
[tool.ruff]
target-version = "py39"
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [tool.ruff] section should be placed before [tool.ruff.lint] section. In TOML files, parent sections should come before their subsections for better organization and clarity. Consider moving the [tool.ruff] section to line 96 (before [tool.ruff.lint]).

Copilot uses AI. Check for mistakes.
@validator("amount", pre=True)
def convert_to_decimal(
cls: Type["DecimalAmount"],
cls: type["DecimalAmount"],
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator parameter type annotation is inconsistent with other validators in the codebase. All other validators use cls: "ClassName" (e.g., cls: "ApiKey" in api_key.py, cls: "Country" in country.py), but this one uses cls: type["DecimalAmount"]. For consistency with Pydantic validator patterns and the rest of the codebase, this should be cls: "DecimalAmount".

Suggested change
cls: type["DecimalAmount"],
cls: "DecimalAmount",

Copilot uses AI. Check for mistakes.
Update pyproject.toml to require pylint ^3.3.0 and regenerate poetry.lock (Poetry 2.2.1) to lock the updated dependencies. This ensures dev tooling uses the newer pylint release and related dependency constraints are refreshed.
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.62%. Comparing base (8b69b3b) to head (2778ba1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #46   +/-   ##
=======================================
  Coverage   90.62%   90.62%           
=======================================
  Files         144      144           
  Lines        2539     2539           
=======================================
  Hits         2301     2301           
  Misses        238      238           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Move and consolidate the [tool.ruff] block in pyproject.toml (add target-version = "py39" and remove duplicate section). Update DecimalAmount.validator signature to use a string forward reference for cls ("DecimalAmount") instead of type[...] to avoid typing/forward-reference issues on Python 3.9 and keep annotations consistet.
@zulquer zulquer requested a review from danielcivit February 27, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants